// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   ajax_businessComment.java

package include.ajax;

import include.get_name_from_ID.getNameFromID;
import include.nseer_db.nseer_db;
import java.sql.ResultSet;
import java.util.Hashtable;
import java.util.StringTokenizer;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class ajax_businessComment
{

	private String ab;
	private String aa;
	private String mo;
	private String path;
	private String value;
	private ServletContext context;
	private HttpSession session;
	private String unit_db_name;

	public ajax_businessComment()
	{
		path = "";
		value = "";
	}

	public void setPath(HttpServletRequest request)
	{
		session = request.getSession();
		context = session.getServletContext();
		String path1 = context.getRealPath("/");
		for (StringTokenizer tokenTO1 = new StringTokenizer(path1, "\\"); tokenTO1.hasMoreTokens();)
		{
			path = (new StringBuilder(String.valueOf(path))).append(tokenTO1.nextToken()).append("/").toString();
			unit_db_name = (String)session.getAttribute("unit_db_name");
		}

	}

	public String getDbName()
	{
		return unit_db_name;
	}

	public String ajax_businessComment(String database, String base, String table_name, String field_name, String field_name1)
	{
		try
		{
			nseer_db db = null;
			db = new nseer_db(unit_db_name);
			getNameFromID dd = new getNameFromID();
			String data = database.substring(0);
			String main_kind_name = "";
			String first_kind_name = "";
			String second_kind_name = "";
			String third_kind_name = "";
			String filename = "";
			String filetype = "";
			StringTokenizer tokenTO = new StringTokenizer(data, "/");
			int tokencount = tokenTO.countTokens();
			switch (tokencount)
			{
			default:
				break;

			case 3: // '\003'
				while (tokenTO.hasMoreTokens()) 
				{
					main_kind_name = tokenTO.nextToken();
					first_kind_name = tokenTO.nextToken();
					filename = tokenTO.nextToken();
				}
				break;

			case 4: // '\004'
				while (tokenTO.hasMoreTokens()) 
				{
					main_kind_name = tokenTO.nextToken();
					first_kind_name = tokenTO.nextToken();
					second_kind_name = tokenTO.nextToken();
					filename = tokenTO.nextToken();
				}
				break;
			}
			for (tokenTO = new StringTokenizer(filename, "."); tokenTO.hasMoreTokens();)
			{
				filename = tokenTO.nextToken();
				filetype = tokenTO.nextToken();
			}

			String group_name = "erp";
			int location = data.indexOf("/");
			String mod = data.substring(0, location);
			String main = dd.getNameFromID((String)session.getAttribute("unit_db_name"), table_name, field_name, mod, field_name1);
			String table = (new StringBuilder(String.valueOf(mod))).append("_tree").toString();
			switch (tokencount)
			{
			default:
				break;

			case 3: // '\003'
				if (filename.indexOf("_") != -1)
					mo = (new StringBuilder("/")).append(main_kind_name).append("/").append(first_kind_name).append("/").append(filename.substring(0, filename.indexOf("_"))).toString();
				else
					mo = (new StringBuilder("/")).append(main_kind_name).append("/").append(first_kind_name).append("/").append(filename).toString();
				break;

			case 4: // '\004'
				if (filename.indexOf("_") != -1)
					mo = (new StringBuilder("/")).append(main_kind_name).append("/").append(first_kind_name).append("/").append(second_kind_name).append("/").append(filename.substring(0, filename.indexOf("_"))).toString();
				else
					mo = (new StringBuilder("/")).append(main_kind_name).append("/").append(first_kind_name).append("/").append(second_kind_name).append("/").append(filename).toString();
				break;
			}
			for (ResultSet rs = db.executeQuery((new StringBuilder("select * from ")).append(table).append(" t where ").append("(t.mainurl REGEXP '[.][.][/][.][.]").append(mo).append("[^a-zA-Z].*'").append(" or t.secondurl REGEXP '[.][.][/][.][.]").append(mo).append("[^a-zA-Z].*'").append(" or t.thirdurl REGEXP '[.][.][/][.][.]").append(mo).append("[^a-zA-Z].*'").append(" or t.fourthurl REGEXP '[.][.][/][.][.]").append(mo).append("[^a-zA-Z].*')").toString()); rs.next();)
			{
				String a = rs.getString("main");
				String b = rs.getString("secondary");
				String c = rs.getString("third");
				if (b.equals(""))
					ab = (new StringBuilder(String.valueOf(getLang("erp", base)))).append(getLang(group_name, main)).append("--").append(getLang(group_name, a)).toString();
				else
				if (c.equals(""))
				{
					ab = (new StringBuilder(String.valueOf(base))).append(a).toString();
					ab = (new StringBuilder(String.valueOf(getLang("erp", base)))).append(getLang(group_name, main)).append("--").append(getLang(group_name, a)).append("--").append(getLang(group_name, b)).toString();
				} else
				{
					ab = (new StringBuilder(String.valueOf(getLang("erp", base)))).append(getLang(group_name, main)).append("--").append(getLang(group_name, a)).append("--").append(getLang(group_name, b)).append("--").append(getLang(group_name, c)).toString();
				}
			}

		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return ab;
	}

	public String getLang(String tablename, String column)
	{
		String unit_db_name = "ondemand1";
		try
		{
			String type = "";
			type = (String)session.getAttribute("language");
			type = (new StringBuilder("multilanguage_")).append(tablename).append("_").append(type).toString();
			Hashtable tt = (Hashtable)context.getAttribute(type);
			value = (String)tt.get(column);
			if (value == null)
			{
				nseer_db db = new nseer_db(unit_db_name);
				value = column;
				tt.put(column, column);
				context.setAttribute(type, tt);
				String sql22 = (new StringBuilder("select * from document_multilanguage where tablename='")).append(tablename).append("' and name='").append(column).append("'").toString();
				ResultSet rs22 = db.executeQuery(sql22);
				if (!rs22.next())
				{
					String sql1 = (new StringBuilder("insert into document_multilanguage(tablename,name)values('")).append(tablename).append("','").append(column).append("')").toString();
					db.executeUpdate(sql1);
				}
				db.close();
			}
		}
		catch (Exception r)
		{
			r.printStackTrace();
		}
		return value;
	}

	public String getLang(ServletContext application, String column)
	{
		nseer_db db = new nseer_db(unit_db_name);
		Hashtable tt = (Hashtable)application.getAttribute("multilanguage_words");
		String value = (String)tt.get(column);
		if (value == null)
		{
			String sql1 = (new StringBuilder("insert into document_multilanguage(tablename,name)values('tree','")).append(column).append("')").toString();
			db.executeUpdate(sql1);
			value = column;
		}
		db.close();
		return value;
	}
}
